export default class Queue {
    private items: any;
    private count: number;
    private header: number;

    constructor() {
        this.items = {};
        this.count = this.header = 0;
    }

    public enqueue(e: any): number {
        this.items[this.count++] = e;
        return this.size();
    }

    public dequeue(): any {
        if (!this.isEmpty()) {
            var e = this.items[this.header];
            delete this.items[this.header];
            this.header++;
            return e;
        }
    }

    public peek(): any {
        if (!this.isEmpty()) return this.items[this.header];
    }

    public size(): number {
        return this.count - this.header;
    }

    public isEmpty(): boolean {
        return 0 === this.size();
    }

    public clear(): void {
        this.items = {};
        this.header = this.count = 0;
    }

    public toString(): string {
        if (this.isEmpty()) return "queue is empty!";
        let str = this.items[this.header].toString();
        for (let t = this.header + 1; t < this.count; t++) {
            str = str + ", " + this.items[t].toString();
        }
        return str;
    }

    public getItems(): any[] {
        const e = [];
        for (const t in this.items) {
            e.push(this.items[t]);
        }
        return e;
    }
}
